/* 人事-基础设置-人员设置api */
import axios from 'axios';
import { getToken } from '@/utils/auth';
import { ajaxService } from '@/utils/request';

const env = import.meta.env;
// const baseURL = env.VITE_APP_BASE_URL;
const baseURL = env.VITE_DEV_BASE_URL;
// const baseURL = 'http://192.168.31.129:39003';
// const baseURL2 = 'http://192.168.31.129:39001';
const baseURL2 = env.VITE_APP_BASE_URL;

// 新增人员花名册表头
export function PostHumanRosterHeaderSetting(data: any) {
  return ajaxService({
    url: '/personnel/header/config',
    method: 'post',
    baseURL: baseURL2,
    data
  });
}

// 新增人员花名册表头
export function PutHumanRosterHeaderSetting(data: any) {
  return ajaxService({
    url: '/personnel/header/config',
    method: 'put',
    baseURL: baseURL2,
    data
  });
}

// 获取人员花名册表头
export function GetHumanRosterHeaderSetting(params: any) {
  return ajaxService({
    url: '/personnel/header/config',
    method: 'get',
    baseURL: baseURL2,
    params
  });
}

// 获取人员花名册列表
export function GetHumanRosterList(params: any) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/list',
    method: 'get',
    baseURL: baseURL,
    params
  });
}

// 获取所属公司或部门下的人员列表
export function GetOrganizationHuman(params: {
  typeName: '公司' | '部门';
  id: number; // 公司或部门id
}) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/photo/page',
    method: 'get',
    baseURL: baseURL,
    params
  });
}

// 获取相同职位直接上级人员列表数据
export function GetHumanImmediateSuperiorList(params: any) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/by/position',
    method: 'get',
    baseURL: baseURL,
    params
  });
}

// 获取人员花名册统计数据
export function GetHumanRosterListNumber() {
  return ajaxService({
    url: '/pl/leave/roster/num',
    method: 'get',
    baseURL
  });
}

// 删除人员花名册列表
export function DelHumanRosterList(data: any) {
  return ajaxService(
    {
      url: '/hr/personnel_matters/roster/personnel/list',
      method: 'delete',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'info' }
  );
}

// 获取人员花名册详情
export function GetHumanRosterDetail(params: any) {
  return ajaxService({
    url: '/hr/personnel_matters/roster/personnel/list/detail',
    method: 'get',
    baseURL,
    params
  });
}

// 编辑人员花名册详情
export function PutHumanRosterDetail(data: any) {
  return ajaxService(
    {
      url: '/hr/personnel_matters/roster/personnel/list/detail',
      method: 'put',
      baseURL,
      data
    },
    {
      mode: 'success',
      message: '保存成功！'
    }
  );
}

// // 导出花名册
// export function ExportHumanRosterList(data: any) {
//   return ajaxService(
//     {
//       url: '/hr/personnel_matters/roster/personnel/list/export',
//       method: 'post',
//       baseURL,
//       headers: {
//         'Content-Type': 'multipart/form-data;charset=UTF-8'
//       },
//       responseType: 'blob',
//       data
//     },
//     {
//       mode: 'success',
//       message: '导出成功!'
//     }
//   );
// }

export async function ExportHumanRosterList(data?: any) {
  return axios({
    method: 'post',
    url: '/hr/personnel_matters/roster/personnel/list/export',
    baseURL,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      Authorization: `${getToken()}`
    },
    responseType: 'blob',
    data
  });
}

// 导出人员花名册列表;
// export function ExportHumanRosterList(data: any) {
//   return ajaxService({
//     url: '/hr/personnel_matters/roster/personnel/list/export',
//     method: 'post',
//     baseURL,
//     // responseType: 'blob',
//     data
//   });
// }
